package test.patterns;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class IteratorMenu implements Iterable<IteratorItem>{

	List<IteratorItem> menuItems;

	public IteratorMenu() {
		menuItems = new ArrayList<IteratorItem>();
	}

	public void addItem(IteratorItem item) {
		menuItems.add(item);
	}

	public Iterator<IteratorItem> iterator() {
		return new MenuIterator();
	}

	class MenuIterator implements Iterator<IteratorItem> {
		int currentIndex = 0;

		@Override
		public boolean hasNext() {
			if (currentIndex >= menuItems.size()) {
				return false;
			} else {
				return true;
			}
		}

		@Override
		public IteratorItem next() {
			return menuItems.get(currentIndex++);
		}

		@Override
		public void remove() {
			menuItems.remove(--currentIndex);
		}

	}

}
